//
//  HYMovieMainView.m
//  KaiJing
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYMovieMainView.h"
#import "UIButton+WebCache.h"
#import "SZYingKUMainViewController.h"
#define movieImageHeight [UIScreen mainScreen].bounds.size.height -  113

@interface HYMovieMainView ()

@end

@implementation HYMovieMainView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addView];
    }
    return self;

}

- (void) addView {
    
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _scrollView.backgroundColor = [UIColor yellowColor];
    
   // _scrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight * 5);
    _scrollView.contentOffset = CGPointMake(0, kScreenHeight);
    _scrollView.bounces = YES;
    _scrollView.pagingEnabled = YES;
    _scrollView.alwaysBounceHorizontal = NO;
    _scrollView.alwaysBounceVertical = YES;
    [self addSubview:_scrollView];

    
    /**注意 这段先用临时的数,等解析好了传过来数组,然后用数组的contont */
    
}

- (void)setArray:(NSMutableArray *)array
{
    _array = array;
    for (int i = 1; i <= array.count; i ++) {
        _model = array[i-1];
        
       
       //大的scrollView
        _scrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight *(i));
        
        //大的图片 因为点击 写成button
        _movieBigImageView = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _movieBigImageView.frame = CGRectMake((kScreenWidth / 5),50 + kScreenHeight *(i - 1), (kScreenWidth / 5) *3, (kScreenHeight / 2));
        _movieBigImageView.backgroundColor = [UIColor redColor];
        NSString *image = [NSString stringWithFormat:@"http://morguo.com/%@",_model.moviedata[@"image"]];
        [_movieBigImageView sd_setBackgroundImageWithURL:[NSURL URLWithString:image] forState:(UIControlStateNormal)];
        [_movieBigImageView addTarget:self action:@selector(image:) forControlEvents:(UIControlEventTouchUpInside)];
        [_scrollView addSubview:_movieBigImageView];
        _movieBigImageView.tag = 1000 + (i - 1);
        
        //大的图片下面的label
        _message = [[UILabel alloc] initWithFrame:CGRectMake(_movieBigImageView.left, _movieBigImageView.bottom + 20, _movieBigImageView.width, 50)];
        _message.backgroundColor = [UIColor redColor];
        _message.text = _model.message;
        _message.numberOfLines = 2;
        _message.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:_message];
        
        //想看的图片
        _thinkButtonImage = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _thinkButtonImage.frame = CGRectMake(kScreenWidth / 20, 50 + _message.bottom, kScreenWidth /10, 30);
        _thinkButtonImage.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_thinkButtonImage];
        
        //想看的button
        _thinkLookButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _thinkLookButton.frame = CGRectMake(_thinkButtonImage.right + 10, _thinkButtonImage.top, _thinkButtonImage.width, _thinkButtonImage.height);
        [_thinkLookButton setTitle:@"想看" forState:(UIControlStateNormal)];
        [_scrollView addSubview:_thinkLookButton];
        _thinkLookButton.backgroundColor = [UIColor redColor];
        
        //看过的图片
        _lookAfterImage = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _lookAfterImage.frame = CGRectMake(_thinkLookButton.right + 10, _thinkLookButton.top, _thinkButtonImage.width, _thinkButtonImage.height);
        _lookAfterImage.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_lookAfterImage];
        
        _lookAfter = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _lookAfter.frame = CGRectMake(_lookAfterImage.right + 10, _thinkLookButton.top, _thinkButtonImage.width, _thinkButtonImage.height);
        [_lookAfter setTitle:@"看过" forState:(UIControlStateNormal)];
        _lookAfter.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_lookAfter];
        
        //分享的button
        _moreButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _moreButton.frame = CGRectMake(kScreenWidth -50, _thinkLookButton.top, _thinkButtonImage.width, _thinkButtonImage.height);
        _moreButton.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_moreButton];
    }
    
}

- (void)image:(UIButton *)button {

    [_delegate changeBigImageButton:button];
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
